package org.chengn.level_middle.context2008;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title: Context2008
 * @Author ChengN
 * @Package org.chengn.level_middle.context2008
 * @Date 2023/12/8 0:38
 * @description: 出租车最大盈利
 */
public class Context2008 {
    public long maxTaxiEarnings(int n, int[][] rides) {
        Map<Integer, List<int[]>> map = new HashMap<>();
        for (int[] ride : rides) {
            List<int[]> list = map.getOrDefault(ride[1], new ArrayList<>());
            list.add(ride);
            map.put(ride[1], list);
        }

        long[] res = new long[n + 1];

        for (int i = 1; i <= n; ++i) {
            res[i] = res[i - 1];
            if (!map.containsKey(i)) {
                continue;
            }
            List<int[]> list = map.get(i);
            for (int[] ls : list) {
                res[i] = Math.max(res[ls[0]] + ls[2] + ls[1] - ls[0], res[i]);
            }
        }
        return res[n];

    }
}
